package com.student.demo.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.student.demo.config.BasicController;
import com.student.demo.entity.Teacher;
import com.student.demo.service.TeacherService;

@RestController
@RequestMapping("teacher")
public class TeacherController extends BasicController {

	@Resource
	private TeacherService teacherService;
	
	@RequestMapping("all")
	//查询所有的教师全部信息 分页查询
	public List<Teacher> findOne(Integer page ) {
	return	teacherService.findAll(page, 10);
	}
	
	//添加教师的基本信息   用到了文件上传
	@RequestMapping("add")
	public Object add(Teacher teacher,MultipartFile file, HttpServletRequest request) {
		String type = file.getContentType();
		String fileName = file.getOriginalFilename();
		 String filePath = request.getSession().getServletContext().getRealPath("imgupload/");
         try {
              uploadFile(file.getBytes(), filePath, fileName);
              teacher.setBimage(fileName);
          } catch (Exception e) {
          }
          //返回json
         
        
	return	success(teacherService.addTeacher(teacher));
	}
	
	@RequestMapping("by_id")
	public Teacher findById(Integer id) {
	return	teacherService.findByBid(id);
	}
	
	
}
